//
//  UserViewController.m
//  TakeHer
//
//  Created by 胖疙瘩的小疙瘩 on 15/6/16.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "UserViewController.h"
#import "AFHTTPRequestOperationManager.h"
#import "User_info.h"
#import "UserTableViewCell.h"
#import "NotesDetailTableViewCell.h"

@interface UserViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, retain) UIImageView *authorImage;
@property (nonatomic, retain) User_info *user_info;
@property (nonatomic, retain) UITableView *tableView;
@property (nonatomic, retain) UIImageView *topImage;
@property (nonatomic, retain) UIImageView *authorImageView;  //作者头像
@property (nonatomic, retain) UILabel *authorName;

@end

@implementation UserViewController

- (void)dealloc
{
    [_userId release];
    [_authorImageView release];
    [_topImage release];
    [_authorName release];
    [_user_info release];
    [_tableView release];
    [super dealloc];
}

//- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
//{
//    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
//    if (self) {
//       
//        
//    }
//}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self createView];
    [self dataHandle];
}


- (void)dataHandle
{
    NSString *str = [NSString stringWithFormat:@"http://api.breadtrip.com/users/%@/v2/", self.userId];
    AFHTTPRequestOperationManager *request = [AFHTTPRequestOperationManager manager];
    request.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"application/json"];
    [request GET:str parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSMutableDictionary *userInfo = [responseObject objectForKey:@"user_info"];
        self.user_info = [[User_info alloc]init];
        [self.user_info setValuesForKeysWithDictionary:userInfo];
        [_user_info release];
/******************************************************/
       // [self addDataHeaderView];
        
/******************************************************/
        [self.tableView reloadData];
        
        
        //[self addDataHeaderView];
        //[self.tabl]
        
        
        
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"%@", error);
    }];
    
}

- (void)createView
{
    self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.tableView];
    
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 300 * self.view.frame.size.height / 667)];
    headerView.backgroundColor = [UIColor cyanColor];
    [self createHeaderView];
    [_tableView release];
}


- (void)createHeaderView {
    self.topImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 280 * self.view.frame.size.height / 667)];
    self.topImage.alpha = 0.5;
    [self.tableView.tableHeaderView addSubview:self.topImage];
    [_topImage release];
    
    self.authorImage = [[UIImageView alloc] initWithFrame:CGRectMake((self.view.frame.size.width - (self.view.frame.size.width / 375 * 100)) / 2, (130 * self.view.frame.size.height / 667) / 2, 100, 100)];
    self.authorImage.layer.masksToBounds = YES;
    self.authorImage.layer.cornerRadius = 50;
    [self.tableView.tableHeaderView addSubview:self.authorImage];
    [_authorImage release];
    
    UIView *authorNameView = [[UIView alloc] initWithFrame:CGRectMake((self.view.frame.size.width - (150 * self.view.frame.size.width / 375)) / 2, (280 * self.view.frame.size.height / 667) / 2, 200 * self.view.frame.size.width / 375, 100 * self.view.frame.size.height / 667)];
    [self.tableView.tableHeaderView addSubview:authorNameView];
    
    self.authorName = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 100)];
    self.authorName.font = [UIFont boldSystemFontOfSize:20];
    self.authorName.textColor = [UIColor whiteColor];
    self.authorName.shadowColor = [UIColor blackColor];
    self.authorName.shadowOffset = CGSizeMake(0, 2);
    [authorNameView addSubview:self.authorName];
    [_authorName release];
    [authorNameView release];
    
    
}
//粉与被粉
//- (void)addDataHeaderView
//{
//    
//}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *str =  @"authorInfomation";
    NotesDetailTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:str];
    if (cell == nil) {
        cell = [[NotesDetailTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:str];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleDefault;
    
    return cell;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
